package com.app.teaware.dialog;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.app.teaware.R;
import com.app.teaware.basis.BasisActivity;
import com.app.teaware.bean.StockListData;
import com.flyco.dialog.widget.NormalDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ResetKWDialog extends NormalDialog {

    @BindView(R.id.edit_kw)
    EditText edit_kw;
    @BindView(R.id.text_code)
    TextView text_code;

    BasisActivity mActivity;
    String nameOrg;

    int max_length = 0;

    OnEditPostListener mListener;
    StockListData stockListData;

    public ResetKWDialog(BasisActivity context, OnEditPostListener listener) {
        super(context);
//            setCanceledOnTouchOutside(false);
        mActivity = context;
        this.mListener = listener;
    }
    public ResetKWDialog(BasisActivity context,StockListData data, OnEditPostListener listener) {
        super(context);
//            setCanceledOnTouchOutside(false);
        mActivity = context;
        this.mListener = listener;
        this.stockListData = data;
    }

    public void setMaxLength(int max){
        this.max_length = max;
    }

    public void setOrgString(String org){
        nameOrg = org;
    }

    @Override
    public View onCreateView() {
//        return super.onCreateView();
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.reset_kw_dialog, null);
        ButterKnife.bind(this, inflate);
        widthScale(0.9f);
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(SystemParamsUtils.getScreenWidth(), LinearLayout.LayoutParams.MATCH_PARENT);
//        recyclerview.setLayoutParams(params);
        setCanceledOnTouchOutside(false);
        return inflate;
    }

    public  void setKW(String kw){
        edit_kw .setText(kw);
    }

    @Override
    public void setUiBeforShow() {
            initData();
    }

    private void initData() {
//        text_code.setText(stockListData.getRfid());
    }


    @OnClick(R.id.btn_cancel)
    void close(){
        if(mListener != null){
            mListener.onCancel();
        }
        dismiss();
    }

    @OnClick(R.id.btn_ok)
    void post(){
        if(TextUtils.isEmpty(edit_kw.getText().toString())){
            mActivity.showToast(edit_kw.getHint()+"");
            return;
        }

        if(mListener != null){
//            mListener.onSubmit(edit_num.getText().toString(),edit_weight.getText().toString());
            mListener.onSubmit(edit_kw.getText().toString());
        }
        dismiss();
    }

    public interface OnEditPostListener {
        abstract void onSubmit(String kwId);
        abstract void onCancel();
    }

}